﻿jQuery.validator.unobtrusive.adapters.add(
	'atleastrequired', ['properties', 'minSelected', 'maxSelected', 'group'], function (options) {
		options.rules['atleastrequired'] = options.params;
		options.messages['atleastrequired'] = options.message;
	}
);

jQuery.validator.addMethod('atleastrequired', function (value, element, params) {
	var properties = params.properties.split(',');
	var minSelected = parseInt(params.minselected);
	var maxSelected = parseInt(params.maxselected);
	var group = params.group; //shouldn't be needed unless you want to highlight the group members

	var values = jQuery.map(properties, function (property, index) {
		var val = jQuery('#' + property).val();
		return val || '' == '' ? val : null;
	});
	return (values.length >= minSelected && values.length <= maxSelected);
}, '');